//
//  LHCityViewController.m
//  Knight_Tour
//
//  Created by Bruce_Lin on 15/5/13.
//  Copyright (c) 2015年 TouchOne. All rights reserved.
//

#import "LHCityViewController.h"
#import "LHCityView.h"
#import "MyNavgationView.h"
#import "LHNetworkHandle.h"
#import "LHCityModel.h"
#import "LHAreaViewController.h"

@interface LHCityViewController ()<jumpToSightDelegate>
@property (nonatomic, retain)LHCityView *cityView;
@property (nonatomic, retain)MyNavgationView *cityNavigation;
@property (nonatomic ,retain)NSMutableArray *cityArr;
@end

@implementation LHCityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.cityArr = [NSMutableArray array];
    [self creatNavigation];
    [self getData];
}

- (void)creatCityView
{
    self.cityView = [[LHCityView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64)];
    _cityView.delegate = self;
    _cityView.CityArr = self.cityArr;
    [self.view addSubview:_cityView];
    [_cityView release];
}

- (void)getData
{
    NSString *url = [NSString stringWithFormat:@"http://119.57.103.173:8080/tsp/regionWSAction!findChildByID.do?regionId=%@",self.myCityID];
    [LHNetworkHandle getDataWithURL:url completion:^(id result) {
       
        for (NSDictionary *tempdic in [result objectForKey:@"regions"]) {
            
            LHCityModel *city = [[LHCityModel alloc]initWithDic:tempdic];
            
            [self.cityArr addObject:city];
            [city release];
        }
        
        [self creatCityView];
    }];
}

- (void)creatNavigation
{
    self.cityNavigation = [[MyNavgationView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
    _cityNavigation.leftTarget = self;
    _cityNavigation.leftAction = @selector(backToProvincePage);
    [_cityNavigation creatLeftButtonWithImage:@"btn_nav_back"];
    [_cityNavigation creatTitle:self.titleName];
    [self.view addSubview:_cityNavigation];
    [_cityNavigation release];
}

- (void)backToProvincePage
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)jumpToSightWithIndexPath:(NSIndexPath *)indexPath
{
    LHAreaViewController *vc = [[LHAreaViewController alloc]init];
    vc.myAreaID = [self.cityArr[indexPath.item] cityID];
    vc.areaTitleName = [self.cityArr[indexPath.item]namec];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    [vc release];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
